﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@MicroAmoy.Util.Config.GetValue("SystemName").ToString()</title>
    <script src="~/Content/scripts/jquery/jquery-1.10.2.min.js"></script>
    <link href="~/Content/styles/learun-login.css" rel="stylesheet" />
    <link href="~/Content/styles/font-awesome.min.css" rel="stylesheet" />
    <script src="~/Content/scripts/plugins/jquery.md5.js"></script>
    <script src="~/Content/scripts/plugins/cookie/jquery.cookie.js"></script>
    <script src="~/Content/scripts/plugins/dialog/dialog.js"></script>
    <script src="~/Content/scripts/utils/learun-ui.js"></script>
    <script src="~/Content/scripts/plugins/validator/validator.js"></script>
    <script src="~/Content/scripts/plugins/tipso.min.js"></script>
    <script>
        var contentPath = '@Url.Content("~")'.substr(0, '@Url.Content("~")'.length - 1);
        var isIE = !!window.ActiveXObject;
        var isIE6 = isIE && !window.XMLHttpRequest;
        if (isIE6) {
            window.location.href = contentPath + "/Error/ErrorBrowser";
        }
        //回车键
        document.onkeydown = function (e) {
            if (!e) e = window.event;
            if ((e.keyCode || e.which) == 13) {
                var btlogin = document.getElementById("btnlogin");
                btnlogin.click();
            }
        }
        //初始化
        $(function () {
            $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
            $(window).resize(function (e) {
                $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
                e.stopPropagation();
            });
            //错误提示
            if (top.$.cookie('learun_login_error') != null) {
                switch (top.$.cookie('learun_login_error')) {
                    case "Overdue":
                        formMessage('登录已超时,请重新登录');
                        break;
                    case "OnLine":
                        formMessage('您的帐号已在其它地方登录,请重新登录');
                        break;
                    case "-1":
                        formMessage('未知错误,请重新登录');
                        break;
                    default:
                        break;
                }
                top.$.cookie('learun_login_error', '', { path: "/", expires: -1 });
            }
            //是否自动登录
            if (top.$.cookie('learn_autologin') == 1) {
                $("#autologin").attr("checked", 'true');
                $("#username").val(top.$.cookie('learn_username'));
                $("#password").val(top.$.cookie('learn_password'));
                CheckLogin(1);
            }
            //设置下次自动登录
            $("#autologin").click(function () {
                if (!$(this).attr('checked')) {
                    $(this).attr("checked", 'true');
                    top.$.cookie('learn_autologin', 1, { path: "/", expires: 7 });
                } else {
                    $(this).removeAttr("checked");
                    top.$.cookie('learn_autologin', '', { path: "/", expires: -1 });
                    top.$.cookie('learn_username', '', { path: "/", expires: -1 });
                    top.$.cookie('learn_password', '', { path: "/", expires: -1 });
                }
            })
            //登录按钮事件
            $("#btnlogin").click(function () {
                var $username = $("#username");
                var $password = $("#password");
                var $verifycode = $("#verifycode");
                if ($username.val() == "") {
                    $username.focus();
                    formMessage('请输入账户或手机号或邮箱。');
                    return false;
                } else if ($password.val() == "") {
                    $password.focus();
                    formMessage('请输入密码。');
                    return false;
                } else if ($verifycode.val() == "") {
                    $verifycode.focus();
                    formMessage('请输入验证码。');
                    return false;
                } else {
                    CheckLogin(0);
                }
            })
            //点击切换验证码
            $("#login_verifycode").click(function () {
                $("#verifycode").val('');
                $("#login_verifycode").attr("src", contentPath + "/Login/VerifyCode?time=" + Math.random());
            });
            //切换注册表单
            $("#a_register").click(function () {
                $("#loginform").hide();
                $("#registerform").show();
                $("#register_verifycode").attr("src", contentPath + "/Login/VerifyCode?time=" + Math.random());
                $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
            });
            //切换登录表单
            $("#a_login").click(function () {
                $("#loginform").show();
                $("#registerform").hide();
                $("#login_verifycode").attr("src", contentPath + "/Login/VerifyCode?time=" + Math.random());
                $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
            });
        })
        //登录验证
        function CheckLogin(autologin) {
            $("#btnlogin").addClass('active').attr('disabled', 'disabled');
            $("#btnlogin").find('span').hide();

            var username = $.trim($("#username").val());
            var password = $.trim($("#password").val());
            var verifycode = $.trim($("#verifycode").val());
            if (top.$.cookie('learn_password') == "" || top.$.cookie('learn_password') == null) {
                password = $.md5(password);
            }
            $.ajax({
                url: contentPath + "/Login/CheckLogin",
                data: { username: $.trim(username), password: $.trim(password), verifycode: verifycode, autologin: autologin },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.type == 1) {
                        if (top.$.cookie('learn_autologin') == 1) {
                            top.$.cookie('learn_username', $.trim(username), { path: "/", expires: 7 });
                            top.$.cookie('learn_password', $.trim(password), { path: "/", expires: 7 });
                        }
                        window.location.href = contentPath + '/Home/AdminDefault';
                    } else {
                        if (data.message.length >= 30) {
                            dialogAlert(data.message, 0)
                        } else {
                            formMessage(data.message);
                        }
                        $("#btnlogin").removeClass('active').removeAttr('disabled');
                        $("#btnlogin").find('span').show();
                        $("#login_verifycode").trigger("click");
                    }
                }
            });
        }
        //提示信息
        function formMessage(msg, type) {
            $('.login_tips').parents('dt').remove();
            var _class = "login_tips";
            if (type == 1) {
                _class = "login_tips-succeed";
            }
            $('.form').prepend('<dt><div class="' + _class + '"><i class="fa fa-question-circle"></i>' + msg + '</div></dt>');
        }



        /*=========注册账户（begin）================================================================*/
        $(function () {
            //手机号离开事件
            $("#txt_register_account").blur(function () {
                if ($(this).val() != "" && !isMobile($(this).val())) {
                    $(this).focus();
                    formMessage('手机格式不正确,请输入正确格式的手机号码。');
                }
                function isMobile(obj) {
                    reg = /^(\+\d{2,3}\-)?\d{11}$/;
                    if (!reg.test(obj)) {
                        return false;
                    } else {
                        return true;
                    }
                }
            });
            //密码输入事件
            $("#txt_register_password").keyup(function () {
                $(".passlevel").find('em').removeClass('bar');
                var length = $(this).val().length;
                if (length <= 8) {
                    $(".passlevel").find('em:eq(0)').addClass('bar');
                } else if (length > 8 && length <= 12) {
                    $(".passlevel").find('em:eq(0)').addClass('bar');
                    $(".passlevel").find('em:eq(1)').addClass('bar');
                } else if (length > 12) {
                    $(".passlevel").find('em').addClass('bar');
                }
            })
            //注册按钮事件
            $("#btnregister").click(function () {
                var $account = $("#txt_register_account");
                var $code = $("#txt_register_code");
                var $name = $("#txt_register_name");
                var $password = $("#txt_register_password");
                var $verifycode = $("#txt_register_verifycode");
                if ($account.val() == "") {
                    $account.focus();
                    formMessage('请输入手机号。');
                    return false;
                } else if ($code.val() == "") {
                    $code.focus();
                    formMessage('请输入短信验证码。');
                    return false;
                } else if ($name.val() == "") {
                    $name.focus();
                    formMessage('请输入姓名。');
                    return false;
                } else if ($password.val() == "") {
                    $password.focus();
                    formMessage('请输入密码。');
                    return false;
                } else if ($verifycode.val() == "") {
                    $verifycode.focus();
                    formMessage('请输入图片验证码。');
                    return false;
                } else {
                    $("#btnregister").addClass('active').attr('disabled', 'disabled');
                    $("#btnregister").find('span').hide();
                    $.ajax({
                        url: contentPath + "/Login/Register",
                        data: { mobileCode: $account.val(), securityCode: $code.val(), fullName: $name.val(), password: $.md5($password.val()), verifycode: $verifycode.val() },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.type == 1) {
                                alert('注册成功');
                                window.location.href = contentPath + '/Login/Index';
                            } else {
                                formMessage(data.message);
                                $("#btnregister").removeClass('active').removeAttr('disabled');
                                $("#btnregister").find('span').show();
                                $("#register_verifycode").trigger("click");
                            }
                        }
                    });
                }
            })
            //获取验证码
            $("#register_getcode").click(function () {
                var $this = $(this);
                $this.attr('disabled', 'disabled');
                $.ajax({
                    url: contentPath + "/Login/GetSecurityCode",
                    data: { mobileCode: $("#txt_register_account").val() },
                    type: "get",
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data.type == 1) {
                            formMessage('已向您的手机' + $("#txt_register_account").val() + '发送了一条验证短信。', 1);
                        } else {
                            $this.removeAttr('disabled');
                            formMessage(data.message);
                        }
                    }
                });
            });
        })
        /*=========注册账户（end）================================================================*/
    </script>
</head>
<body class="aaabody">
    
    <div class="wrap">
        <div style="text-align: center;">
            <img src="~/Content/images/on-line.png" style="border-radius: 96px; margin-bottom: -48px;" />
        </div>
        <div id="loginform" class="container">
            <fieldset class="box">
                <legend>登录伙伴</legend>
                <dl class="form">
                    <dd>
                        <input id="username" type="text" class="px" placeholder="账户、邮箱或手机号"></dd>
                    <dd>
                        <input id="password" type="password" class="px" placeholder="密码"></dd>
                    <dd style="overflow: hidden;">
                        <div style="float: left; width: 65%">
                            <input id="verifycode" maxlength="4" type="text" class="px" placeholder="图片验证码">
                        </div>
                        <div style="float: left; width: 35%">
                            <img id="login_verifycode" class="img_verifycode" src="~/Login/VerifyCode" width="100" height="30" alt="点击切换验证码"
                                title="点击切换验证码" style="cursor: pointer; padding-top: 2px; padding-left: 5px;" />
                        </div>
                    </dd>
                    <dd>
                        <span class="y"><a href="#" onclick="alert('请联系管理员')">忘记密码了？</a></span>
                        <label style="cursor: pointer;">
                            <input id="autologin" type="checkbox" class="pc" style="margin-bottom: 4.5px; margin-right: 0px; vertical-align: middle;">
                            <span>下次自动登录</span>
                        </label>
                    </dd>
                    <dd class="btn">
                        <button id="btnlogin" type="button" class="pn"><span>登录</span></button>

                    </dd>
                </dl>
            </fieldset>
        </div>
        <div id="registerform" class="container" style="display: none;">
            <fieldset class="box">
                <legend>注册信息</legend>
                <dl class="form">
                    <dd>
                        <input id="txt_register_account" maxlength="11" type="text" class="px" placeholder="手机号">
                    </dd>
                    <dd style="overflow: hidden;">
                        <div style="float: left; width: 223px;">
                            <input id="txt_register_code" maxlength="6" type="text" class="px" placeholder="短信验证码">
                        </div>
                        <div style="float: left;">
                            <button id="register_getcode" type="button" class="pn_getcode">获取验证码</button>
                        </div>
                    </dd>
                    <dd>
                        <input id="txt_register_name" type="text" class="px" placeholder="姓名"></dd>
                    <dd style="margin-bottom: 5px;">
                        <input id="txt_register_password" type="password" class="px" placeholder="密码">
                        <p class="info">密码长度为8~30个字符，需包含字母和数字</p>
                        <span class="passlevel"><em></em><em></em><em></em></span>
                    </dd>
                    <dd style="overflow: hidden;">
                        <div style="float: left; width: 65%">
                            <input id="txt_register_verifycode" maxlength="4" type="text" class="px" placeholder="图片验证码">
                        </div>
                        <div style="float: left; width: 35%;">
                            <img id="register_verifycode" width="100" height="30" alt="点击切换验证码" title="点击切换验证码" style="cursor: pointer; padding-top: 2px; padding-left: 5px;" />
                        </div>
                    </dd>
                </dl>
            </fieldset>
        </div>
    </div>
    <div class="copyright">
        云云科技工作室出品
    </div>
</body>
</html>
